#include <bits/stdc++.h>

using namespace std;
int N, L;
const int maxn = 80 + 5;
int ans[maxn];

int cnt;

bool solve(int cur) {
    if (cnt++ == N) {
        for (int i = 1; i <= cur; ++i) {
            cout << (char) (ans[i - 1] + 'A');
            if (i == cur || i % 64 == 0) cout << "\n";
            else if (i % 4 == 0) cout << " ";
        }
        cout << cur << "\n";
        return true;
    }
    for (int i = 0; i < L; ++i) {
        ans[cur] = i;
        bool same;

        for (int s = 1; s * 2 <= cur + 1; ++s) {
            same = true;
            for (int p = cur - s + 1; p <= cur; ++p) {
                if (ans[p] != ans[p - s]) {
                    same = false;
                    break;
                }
            }
            if (same) break;
        }

        if (!same) if (solve(cur + 1)) return true;
    }
    return false;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    while (cin >> N >> L && N && L) {
        cnt = 0;
        memset(ans, -1, sizeof(ans));
        solve(0);
    }
    return 0;
}